# 测试 Swagger 文档注释的 PowerShell 脚本
# 作用：验证 API 端点的中文注释是否正确显示在 Swagger UI 中

Write-Host "🔍 测试 SmartMedicalRAG API 的 Swagger 文档注释..." -ForegroundColor Green

# 等待 API 启动
Write-Host "⏳ 等待 API 启动..." -ForegroundColor Yellow
Start-Sleep -Seconds 5

# 测试 Swagger JSON 端点
Write-Host "📋 获取 Swagger JSON 文档..." -ForegroundColor Cyan
try {
    $swaggerJson = Invoke-RestMethod -Uri "https://localhost:56704/swagger/v1/swagger.json" -Method Get
    Write-Host "✅ Swagger JSON 获取成功" -ForegroundColor Green
    
    # 检查控制器和端点的注释
    Write-Host "`n📝 检查 API 端点注释..." -ForegroundColor Cyan
    
    if ($swaggerJson.paths) {
        Write-Host "`n🔗 可用的 API 端点：" -ForegroundColor Yellow
        
        foreach ($path in $swaggerJson.paths.PSObject.Properties) {
            $pathName = $path.Name
            $pathObj = $path.Value
            
            foreach ($method in $pathObj.PSObject.Properties) {
                $methodName = $method.Name.ToUpper()
                $methodObj = $method.Value
                
                $summary = $methodObj.summary
                $description = $methodObj.description
                
                Write-Host "`n  $methodName $pathName" -ForegroundColor White
                if ($summary) {
                    Write-Host "     📋 摘要: $summary" -ForegroundColor Gray
                }
                if ($description) {
                    Write-Host "     📄 描述: $description" -ForegroundColor Gray
                }
            }
        }
    }
    
    # 检查数据模型
    Write-Host "`n📊 检查数据模型注释..." -ForegroundColor Cyan
    if ($swaggerJson.definitions) {
        Write-Host "`n🏗️  可用的数据模型：" -ForegroundColor Yellow
        
        foreach ($model in $swaggerJson.definitions.PSObject.Properties) {
            $modelName = $model.Name
            $modelObj = $model.Value
            
            $description = $modelObj.description
            Write-Host "`n  📋 $modelName" -ForegroundColor White
            if ($description) {
                Write-Host "     📄 描述: $description" -ForegroundColor Gray
            }
        }
    }
    
} catch {
    Write-Host "❌ 无法获取 Swagger 文档: $($_.Exception.Message)" -ForegroundColor Red
    Write-Host "💡 请确保 API 正在运行，并且可以访问 https://localhost:56704" -ForegroundColor Yellow
}

Write-Host "`n🌐 您可以在浏览器中访问以下地址查看 Swagger UI：" -ForegroundColor Green
Write-Host "   https://localhost:56704/swagger" -ForegroundColor Cyan
Write-Host "`n📖 在 Swagger UI 中，您应该能看到：" -ForegroundColor Yellow
Write-Host "   ✅ 所有端点的中文注释和描述" -ForegroundColor Green
Write-Host "   ✅ 数据模型的详细说明" -ForegroundColor Green
Write-Host "   ✅ 请求和响应的示例" -ForegroundColor Green
Write-Host "   ✅ 状态码的说明" -ForegroundColor Green

Write-Host "`n🎯 测试完成！" -ForegroundColor Green 